package com.wiscamp.ninechapters.problems.infrastructure.mappers.collections;

import com.wiscamp.ninechapters.problems.infrastructure.po.collections.CollectionSectionPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

/**
 * 题集试卷节仓储对象
 *
 * @author yifeng
 */
@Repository
public interface CollectionSectionMapper extends JpaRepository<CollectionSectionPO, Long>, JpaSpecificationExecutor<CollectionSectionPO> {
    /**
     * 通过部分编号获取题集节列表
     *
     * @param partId
     * @return
     */
    @Query(value = "select s from CollectionSectionPO s where s.partId = :partId order by s.sectionIndex asc")
    Collection<CollectionSectionPO> findListByPart(long partId);

    /**
     * 通过部分编号和题集节编号获取题集节
     *
     * @param partId
     * @param sectionId
     * @return
     */
    @Query(value = "select s from CollectionSectionPO s where s.partId = :partId and s.sectionId = :sectionId order by s.sectionIndex asc")
    CollectionSectionPO findByPartAndSection(long partId, long sectionId);
}